
from basic.base import BaseRequest

class URL:
    MEMBER_LIST = "adminapi/member/member"
    MEMBER_ADD = "adminapi/member/member"
    MEMBER_MODIFY = "adminapi/member/member/modify"
    MEMBER_MASSAGE = "adminapi/member/member/"
    MEMBER_LABEL_LIST = "adminapi/member/label"
    MEMBER_LABEL_ADD = "adminapi/member/label"
    MEMBER_LABEL_MODIFY = "adminapi/member/label"
    MEMBER_LABEL_MASSAGE = "adminapi/member/label"
    MEMBER_LABEL_DELETE = "adminapi/member/label"
    MEMBER_LEVEL_LIST = "adminapi/member/level"
    MEMBER_LEVEL_ADD = "adminapi/member/level"
    MEMBER_ACCOUNT_BALANCE = "adminapi/member/account"
    MEMBER_ACCOUNT_COMMISSION = "adminapi/member/account/commission"

class Member(URL,BaseRequest):

    def member_list(self,keyword = None,register_type = None,member_label = None,register_channel = None,member_level = None):                                                      # 会员列表
        data = {
                "page": 1,
                "limit": 10,
                "keyword": keyword,
                "register_type": register_type,
                "member_label": member_label,
                "register_channel": register_channel,
                "member_level": member_level,
        }
        return self._get(api_name=self.member_list.__name__ ,url=self.MEMBER_LIST,params=data).json()

    def member_add(self,nickname,member_no,init_member_no,mobile,password,password_copy,member_id=None):                                                       # 会员添加
        """
                添加会员
                :param member_no:会员编号
                :param nickname:会员昵称
                :param mobile:手机号
                :param password:密码
                :param password_copy:重复密码
                """
        data = {
                "member_id": member_id,
                "nickname": nickname,
                "member_no": member_no,
                "init_member_no": init_member_no,
                "mobile": mobile,
                "password": password,
                "password_copy": password_copy
        }
        return self._post(api_name=self.member_add.__name__,url=self.MEMBER_ADD, data=data).json()

    def member_modify(self,member_id,filed,value):
        """
        会员编辑
        :param member_id:会员id
        :param filed:sex:性别 0:保密 1:男 2:女 / member_label:会员标签 / member_level:会员等级 /
        """
        data = {
            "member_id": member_id,
            "filed": filed,
            "value" : value
        }
        return self._put(api_name=self.member_modify.__name__,url=self.MEMBER_MODIFY+f"/{member_id}/{filed}", data =data).json()

    def member_message(self,member_id):                                                   # 会员信息
        data = {}
        return self._get(api_name=self.member_message.__name__,url=self.MEMBER_MASSAGE+f"/{member_id}", params=data).json()

    def member_label_list(self,page=None,limit=None,label_name=None):
        data =  {'page': page,'limit': limit,'label_name': label_name}
        return self._get(api_name=self.member_label_list.__name__,url=self.MEMBER_LABEL_LIST, params=data).json()

    def member_label_add(self,label_name,memo,sort,label_id=None):
        """
                        添加会员标签
                        :param label_name:标签名称
                        :param memo:标签备注
                        :param sort:排序
                        :param label_id:标签ID
        """
        data = {
                "label_name": label_name,
                "label_memo": memo,
                "sort": sort,
                "label_id": label_id
        }
        return self._post(api_name=self.member_label_add.__name__,url=self.MEMBER_LABEL_ADD,data =data).json()

    def member_label_delete(self,label_id):
        """
                        删除会员标签
                        :param label_id:标签id
         """
        data = {}
        return self._delete(api_name=self.member_label_delete.__name__,url=self.MEMBER_LABEL_DELETE+f"/{label_id}", params=data).json()

    def member_label_modify(self,label_id, label_name, memo=None, sort=None):
        """
                        编辑标签
                        :param label_name:标签名称
                        :param memo:标签备注
                        :param sort:排序
                        :param label_id:标签ID
        """
        data =  {'label_id': label_id, 'label_name': label_name, 'memo': memo, 'sort': sort}
        print(self.MEMBER_LABEL_MODIFY+f"/{label_id}")
        return self._put(api_name=self.member_label_modify.__name__,url=self.MEMBER_LABEL_MODIFY+f"/{label_id}", data=data).json()

    def member_account_balance(self,page,limit,keywords=None,from_type=None,create_time=None,mobile=None,member_id=None,balance_type=None):
        data = {
            "page" : page,
            "limit" : limit,
            "keywords" : keywords,
            "from_type" : from_type,
            "create_time" : create_time,
            "mobile" : mobile,
            "member_id" : member_id,
            "balance_type" : balance_type
        }
        return self._get(api_name=self.member_account_balance.__name__,url=self.MEMBER_ACCOUNT_BALANCE, params=data).json()

    def member_account_commission(self,page,limit, member_id,keywords=None,from_type=None,create_time=None,mobile=None):                                        # 账户佣金
        """
                        账户佣金
        """
        data =  {
                "page": page,
                "limit": limit,
                "keywords": keywords,
                "from_type": from_type,
                "create_time": create_time,
                "mobile": mobile,
                "member_id": member_id,
        }
        return self._get(api_name=self.member_account_commission.__name__,url=self.MEMBER_ACCOUNT_COMMISSION, params=data).json()

    def member_level_list(self,page = None,limit = None,level_name = None):
        """
                        会员等级列表
                        :param page:
                        :param limit:
                        :param level_name: 等级名称
                        :return:
        """
        data = {
            "page" : page,
            "limit" : limit,
            "level_name" : level_name
        }
        return self._get(api_name=self.member_level_list.__name__,url=self.MEMBER_LEVEL_LIST, params=data).json()

    def member_level_add(self,level_name,remark,growth,level_benefits,level_gifts):
        """
         会员等级添加
         :param level_name: 等级名称
         :param remark: 等级备注
         :param growth: 成长值
         :param level_benefits: 等级权益  {discount: {is_use: 1, discount: "7"}
                                 :param is_use: 1:启用 0:禁用 , discount 折扣(0.1~9.9)
         :param level_gifts: 等级赠品 {balance: {is_use: 1, money: "12"}, point: {is_use: 1, num: "13"}
                                 :param is_use: 1:启用 0:禁用, money: x元红包, num: x积分
        """
        data ={
    'level_id': 0,
    'level_name': level_name,
    'remark': remark,
    'growth': growth,
    'level_benefits': level_benefits,
    'level_gifts': level_gifts,
}
        return self._post(api_name=self.member_level_add.__name__,url=self.MEMBER_LEVEL_ADD, data=data).json()


if __name__ == '__main__':
    member = Member()
    #member.member_label_modify(label_id=359,label_name="啊啊123",memo="123",sort="123")
    member.member_label_list()
